package smallChanges.statements;

import java.util.List;

import net.sourceforge.pmd.ast.ASTVariableDeclarator;
import net.sourceforge.pmd.ast.ASTVariableDeclaratorId;
import net.sourceforge.pmd.ast.JavaParserVisitorAdapter;
import smallChanges.Tokenization.TokenSet;
import smallChanges.util.SCConstants;

public class VariableVisitor extends JavaParserVisitorAdapter implements SCConstants {
		private SCType type;
		private TokenSet tokenSet;
		
		public VariableVisitor(TokenSet tokenSet) {
		    this.tokenSet=tokenSet;
		}
		
		public void setType(SCType type)
		{
			this.type = type;
		}
		
		@Override
        public Object visit(ASTVariableDeclarator node, Object data)
        {
		    if (data instanceof List) {
		        List<FieldDeclarationStatement> list=(List<FieldDeclarationStatement>)data;
		        FieldDeclarationStatement fds=new FieldDeclarationStatement(tokenSet);
                fds.setCoordinatesFromNode(node);
                fds.setName(node.getImage());
                fds.setType(type);
                node.childrenAccept(this, fds);
                list.add(fds);
		        return list;
		    }
            return super.visit(node, data);
        }

        public Object visit(ASTVariableDeclaratorId node, Object data)
	    {
	    	if (data instanceof FieldDeclarationStatement)
	    	{
	    		FieldDeclarationStatement fds=(FieldDeclarationStatement)data;
	            fds.setName(node.getImage());
	            return fds;
	    	}
	    	return super.visit(node, data);
	    }

}
